/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package junchangmis.student;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import publicmethod.*;
import java.sql.ResultSet;
import java.util.*;

/**
 *
 * @author developers
 */
public class stuChooseMethod {

    public static boolean hasFormalStu(String id, formalStu student) {//根据学号查询有无此学生 并返回该学生的所有信息
        try {
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select * from formalStu where id='" + id + "'";
            ResultSet rs = db.DBSqlQuery(sql);
            if (rs.next()) {
                student.id = rs.getString("id");
                student.name = rs.getString("name");
                student.sex = rs.getString("sex");
                student.birthday = rs.getString("birthday");
                student.tel = rs.getString("tel");
                student.school = rs.getString("school");
                student.weekCount = rs.getString("weekCount");
                student.dateStart = rs.getString("dateStart");
                student.coursePerWeek = rs.getString("coursePerWeek");
                student.pricePerCourse = rs.getString("pricePerCourse");
                student.tuition = rs.getString("tuition");
                student.costumeFee = rs.getString("costumeFee");
                student.bookFee = rs.getString("bookFee");
                student.otherFee = rs.getString("otherFee");
                student.sumFee = rs.getString("sumFee");
                student.classCode = rs.getString("classCode");
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(stuChooseMethod.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public static boolean hasFormalStu(String id) {//根据学号查询有无此学生 仅查询
        try {
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select * from formalStu where id='" + id + "'";
            ResultSet rs = db.DBSqlQuery(sql);
            if (rs.next()) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(stuChooseMethod.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public static boolean hasFormalStuAsName(String name, Vector<formalStu> stuName) {
        try {
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select * from formalStu where name='" + name + "'";
            ResultSet rs = db.DBSqlQuery(sql);
            while (rs.next()) {
                formalStu student = new formalStu();
                student.id = rs.getString("id");
                student.name = rs.getString("name");
                student.sex = rs.getString("sex");
                student.birthday = rs.getString("birthday");
                student.tel = rs.getString("tel");
                student.school = rs.getString("school");
                student.weekCount = rs.getString("weekCount");
                student.dateStart = rs.getString("dateStart");
                student.coursePerWeek = rs.getString("coursePerWeek");
                student.pricePerCourse = rs.getString("pricePerCourse");
                student.tuition = rs.getString("tuition");
                student.costumeFee = rs.getString("costumeFee");
                student.bookFee = rs.getString("bookFee");
                student.otherFee = rs.getString("otherFee");
                student.sumFee = rs.getString("sumFee");
                student.classCode = rs.getString("classCode");

                stuName.add(student);
            }
            if (stuName.size() > 0) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(stuChooseMethod.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
}
